;Search and Replace TEXT; copyright 1996, H.C. Francis
;
;	AUTHOR: HENRY C. FRANCIS
;		425 N. ASHE ST.
;		SOUTHERN PINES, NC 28387
;              
;		All rights reserved without prejudice.
;	Copyright:	8-8-97
;	Edited:		8-8-97
;
(defun c:rxact ( / tset sslen count cstrl nstrl cind strlm tent tstr strl
str1 str2 istr)
  (setq chstr (ustr 1 "String to search for" chstr "T")
        nwstr (ustr 0 "String to replace it" nwstr "T")
        chngit nil
        getstr (read(strcat "((-4 . \"<AND\")(0 . \"TEXT\")(1 . \"" chstr "\")(-4 . \"AND>\"))"))
  )
  (setq tset (ssget "x" getstr))
  (if tset
    (setq sslen (sslength tset))
    (setq sslen 0)
  )
  (setq count 0
        match# 0
        cv_max (getvar"vsmax")
        cv_min (getvar"vsmin")
        vptd1 (/(getvar"viewsize")50)
        vptd2 (/(getvar"viewsize")40)
  )
  (while (and(not(>= count sslen))(/= "Quit" chngit))
;    (PRINC "\nENTER 1ST WHILE")
    (setq tent (entget(ssname tset count))
          tstr (cdr(assoc 1 tent))
          strl (strlen tstr)
    )
    (setq txtpnt (cdr(assoc 10 tent)))
;    (if (or
;
;        )
;    )
    (setq cv_ctr (getvar"viewctr")
          vptd1 (/(getvar"viewsize")10)
          vpt11 (polar txtpnt (* pi 0.25) vptd1)
          vpt12 (polar txtpnt (* pi 0.75) vptd1)
          vpt13 (polar txtpnt (* pi 1.25) vptd1)
          vpt14 (polar txtpnt (* pi 1.75) vptd1)
    )
    (grvecs
      (list 256 vpt11 vpt13
            256 vpt12 vpt14
      )
    )
    (if (/= chngit "GLobal")
      (setq chngit (ukword 1 "Yes No GLobal Quit" (strcat "Change this \"" chstr "\" text? [Yes/No/GLobal/Quit] ") chngit))
    )
    (if (or(eq chngit "Yes")(eq chngit "GLobal"))
      (progn
        (setq tent (subst (cons 1 nwstr)(assoc 1 tent)tent))
        (entmod tent)
        (entupd (cdar tent))
        (setq match# (1+ match#))
      )
    )
    (if (equal cv_ctr (getvar"viewctr") 0.00001)
      (grvecs
        (list 256 vpt11 vpt13
              256 vpt12 vpt14
        )
      )
      (setq cv_ctr (getvar"viewctr"))
    )
    (setq count (1+ count))
  );while
  (if (and(/= chngit "Quit")(= match# 0))
    (princ "\No matching text found. ")
    (princ (strcat "\n" (itoa match#) " \"" chstr "\" strings were replaced with \"" nwstr "\" strings."))
  )
  (princ)
);defun
